package org.ucas.faker.web.utils.fishbone;

import java.util.ArrayList;
import java.util.List;

public class FishboneNode {

    private int id = 0;
    private String tag = "empty";
    private FishboneNode parent = null;
    private List<FishboneNode> childrenList = new ArrayList<FishboneNode>();
    private int level = 0;
    private int count = 0;
    private List<String> patentList = new ArrayList<String>();

    private double[] startPosition;
    private double[] tagPosition;

    public List<String> getPatentList() {
        return patentList;
    }

    public void setPatentList(List<String> patentList) {
        this.patentList = patentList;
    }

    public void addPatent(String patent){
        if (this.patentList == null){
            this.patentList = new ArrayList<String>();
        }
        if (!this.patentList.contains(patent)){
            this.patentList.add(patent);
        }
    }

    public void addPatent(List<String> patents){
        if (this.patentList == null){
            this.patentList = new ArrayList<String>();
        }
        for (String tmp : patents){
            if (!this.patentList.contains(tmp)){
                this.patentList.add(tmp);
            }
        }
    }

    public double[] getStartPosition() {
        return startPosition;
    }

    public double[] getTagPosition() {
        return tagPosition;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getCount() {
        return count;
    }

    public void addCount(){
        this.count ++;
    }

    public void setStartPosition(double x, double y) {
        double[] p = {x, y};
        this.startPosition = p;
    }

    public void setTagPosition(double x, double y) {
        double[] p = {x, y};
        this.tagPosition = p;
    }

    public FishboneNode(int id, String tag){
        this.tag = tag;
        this.id = id;
        this.childrenList = new ArrayList<FishboneNode>();
    }

    public FishboneNode(String tag){
        this.tag = tag;
        final double d = Math.random();
        final int i = (int)(d*1000);
        final long l = System.currentTimeMillis();
        final int j = (int)( l % 100 );

        this.id = i*100+j;
        this.childrenList = new ArrayList<FishboneNode>();
    }

    public int getId() {
        return id;
    }

    public int getLevel() {
        return level;
    }

    public String getTag() {
        return tag;
    }

    public List<FishboneNode> getChildrenList() {
        return childrenList;
    }

    public FishboneNode getParent() {
        return parent;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public void setParent(FishboneNode parent) {
        this.parent = parent;
    }

    public void setChildrenList(List<FishboneNode> childrenList) {
        this.childrenList = childrenList;
    }

    public void addChild(FishboneNode child){
        this.childrenList.add(child);
    }

    public void printTree(){
        System.out.println("id:"+this.id+"  tag:"+this.tag);
        if (this.getChildrenList().size()>0) {
            System.out.println("children");
        }
        for (FishboneNode node : this.getChildrenList()){
            System.out.println("----->  id:"+node.getId()+"  tag:"+node.getTag());
        }
        System.out.println();

        for (FishboneNode node : this.getChildrenList()){
            node.printTree();
        }

    }

}
